﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>验证字符串是否全由数字组成</title>
    <script type="text/javascript" language="JavaScript">
        function checkNum(str){
            if(str.match(/\d/) === null){
                alert("输入数值错误");
            }else{
                alert("数值正确");
            }
        }
    </script>
    
</head>
<body>
<input type=text name="txt1" value="a">
<input type=button name="btn1" value="测试" onclick="checkNum(txt1.value)">
</body>
</html>